home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 January / Cd Pc Users extra 16 enero 1999.iso / prog / inst / killapp / killapp.bas next >
Encoding:
BASIC Source File  |  1997-08-04  |  1.2 KB  |  36 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. Declare Function EnumWindows Lib "user32" (ByVal wndenmprc As Long, ByVal lParam As Long) As Long
  5. Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  6. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  7. Public Const WM_CLOSE = &H10
  8.  
  9. Private Target As String
  10. ' Check a returned task to see if we should
  11. ' kill it.
  12. Public Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
  13. Dim buf As String * 256
  14. Dim title As String
  15. Dim length As Long
  16.  
  17.     ' Get the window's title.
  18.     length = GetWindowText(app_hWnd, buf, Len(buf))
  19.     title = Left$(buf, length)
  20.  
  21.     ' See if this is the target window.
  22.     If InStr(title, Target) <> 0 Then
  23.         ' Kill the window.
  24.         SendMessage app_hWnd, WM_CLOSE, 0, 0
  25.     End If
  26.     
  27.     ' Continue searching.
  28.     EnumCallback = 1
  29. End Function
  30.  
  31. ' Ask Windows for the list of tasks.
  32. Public Sub TerminateTask(app_name As String)
  33.     Target = app_name
  34.     EnumWindows AddressOf EnumCallback, 0
  35. End Sub
  36.